home *** CD-ROM | disk | FTP | other *** search
- Path: beta.nedernet.nl!usenet
- From: jos@and.nl (Jos A. Horsmeier)
- Newsgroups: comp.lang.c
- Subject: Re: Int to Double, Pl Advise!
- Date: 29 Mar 1996 14:43:26 GMT
- Organization: AND Operations Research B.V.
- Message-ID: <4jgsuf$2ll@beta.nedernet.nl>
- References: <isa5224.544.315B647A@age2.age.uiuc.edu>
- NNTP-Posting-Host: klepzeiker.and.nl
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <isa5224.544.315B647A@age2.age.uiuc.edu>, isa5224@age2.age.uiuc.edu
- wrote:
-
- [ stripped, but kepped the essentials: ]
- |#define Ng 4
- |#define Nr 4
- |
- |int p0[Ng][Nr];
- |
- | x = x + ((double) p0[i,j]) / (double)(j*j); }
- |
- |I get the following compilation error(s) on MS C++ compiler:
- |error C2440: 'cast' : cannot convert from 'int [4]' to 'double '
-
- When K&R designed the C language, one of their evil goals was
- to pester as many Pascalian victims as possible. These two villains
- did not just decide to make the assignment token to be a simple '=',
- 'cause those Pascalian rascals would manage to figure out that little
- pitfall within a couple of hundred runtime errors and an occasional
- compiler diagnostic; they even decided that the Pascal array notation
- would seem valid, sound and solid in C. And, syntactically speaking,
- it is; 'p0[i, j]' is perfectly legal C, but, (insert diabolical laughter
- here), it doesn't mean what it it looks like. You've been poo-poo'd by
- a cleverly disguised neo-Babylonian-C-trap. (diabolical laughter again).
-
- The expression 'i,j' means: evaluate 'i', discard the resulting value,
- and evaluate 'j' afterwards. The result of the entire expression equals
- the value of 'j'. You could have written 'p0[j]' here instead.
-
- The nasty scoundrels they are, K&R _wanted_ you to write 'p0[i][j]', meaning:
- 'p0[i]' is an array of 'things', where each 'thing' is an array of 'Nr'
- ints, so p0[i][j] denotes the i-th 'thing' where 'j' indexes the
- int element in that 'thing' you were looking for ...
-
- kind regards,
-
- Jos aka jos@and.nl
- --
- Atnwgqkrl gy zit vgksr, ug qshiqwtzoeqs!
-
-